package com.hadoop.mapReduce.wordCountMine.ioDemo;

import com.hadoop.mapReduce.wordCountMine._01MyContext;
import com.hadoop.mapReduce.wordCountMine._02MyMapper;


public class _03WordCountMapper implements _02MyMapper {

    public void map(String line, _01MyContext context) {
        //line = "The Project  Project Gutenberg EBook of Pride and Prejudice, by Jane Austen"
        String[] words = line.split(" ");
        //words = [The,Project,Project,Gutenberg ....]

        //todo 词频需求的核心逻辑
        for(String word : words) {
            //word1 = The  word2 = Project word3=Project
            Object value = context.get(word);
            if(value == null) { // 表示没有出现过该单词
                context.write(word, 1);//(The,1)  (Project,1)
            } else {
                int v = Integer.parseInt(value.toString());//1
                context.write(word, v+1);  // 取出单词对应的次数+1 (Project,2)
            }
        }

    }
}
